const cheerio = require('cheerio');
module.exports = (options = {}) => {

	return async(ctx, next) => {
		await next();
		if(!ctx.isRedirect() && ctx.isPjax()) {
			let $ = cheerio.load(ctx.body);
//			console.log(ctx.body)
			let title = $.html('title');
			let pjaxElement = ctx.pjaxContainer(ctx);
			if(pjaxElement) {
				let container = $.html(pjaxElement);

				ctx.set('X-PJAX-URL', ctx.href);
				ctx.body = title + container;
			}

		}

	}

}